home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcplusx.zip / CURSOR.CPP next >
C/C++ Source or Header  |  1991-02-28  |  6KB  |  223 lines

  1. //
  2. // cursor.cpp    - implementation for class Cursor
  3. // Author        - Robin W. McKean
  4. // Last Update    - February 23,1991
  5. // Copyright (C) 1991 All rights reserved
  6. //
  7. // This file remains the property of the author, Robin W. McKean.  You are
  8. // free to use and change it as you see fit.  This module, nor its object
  9. // code, may not however be included  in any packaged software without the
  10. // written consent of the author.
  11. //
  12.  
  13. // Contents ----------------------------------------------------------------
  14. //
  15. //        Cursor::Cursor
  16. //        Cursor::isA
  17. //        Cursor::nameOf
  18. //        Cursor::processA
  19. //        Cursor::pollDevice
  20. //
  21. // Description
  22. //
  23. //      Defines the class Cursor.  The purpose of this class is to allow
  24. //      the cursor to be used as an ordinary device.  Not for input, but to
  25. //        moved around and transformed by objects through events
  26. //            
  27. // End ---------------------------------------------------------------------
  28.  
  29. // Interface dependencies --------------------------------------------------
  30.  
  31. #ifndef _IOSTREAM_H
  32. #include <iostream.h>
  33. #endif
  34.  
  35. #ifndef _USETYPES_H
  36. #include <usetypes.h>
  37. #endif
  38.  
  39. #ifndef _GEN_H
  40. #include <gen.h>
  41. #endif
  42.  
  43. #ifndef _EVENT_H
  44. #include <event.h>
  45. #endif
  46.  
  47. #ifndef _CURSOR_H
  48. #include <cursor.h>
  49. #endif
  50.  
  51. // End Interface dependencies ----------------------------------------------
  52.  
  53. // Implementation dependencies ---------------------------------------------
  54.  
  55. #ifndef _DOS_H
  56. #define _DOS_H
  57. #include <dos.h>
  58. #endif
  59.  
  60. #ifndef _CONIO_H
  61. #define _CONIO_H
  62. #include <conio.h>
  63. #endif
  64.  
  65. // End Implementation dependencies -----------------------------------------
  66.  
  67. // Member Function //
  68.  
  69. Cursor::Cursor( int initStatus ) : Device( initStatus )
  70.  
  71. // Summary ------------------------------------------------------------------
  72. //
  73. //        Sets the initial status of the cursor.    It saves some of the defaults
  74. //        of the cursor, so they can be restored when this object is destroyed
  75. //
  76. // End ---------------------------------------------------------------------
  77. {
  78.     REGS regs;
  79.  
  80.     // Set the device type
  81.     type = D_CURSOR;
  82.  
  83.     // Read the cursor size and position, using the BIOS
  84.     regs.h.ah = 3;
  85.     regs.h.bh = 0;
  86.     int86( 0x10, ®s, ®s );
  87.  
  88.     // Save the cursor size and position
  89.     initialCursorState = _NORMALCURSOR;
  90.     line = ( unsigned int ) regs.h.dh;
  91.     column = ( unsigned int ) regs.h.dl;
  92.  
  93.     currentCursorState = oldCursorState = initialCursorState;
  94.     if( status == D_ON ) _setcursortype( _NORMALCURSOR );
  95.     else _setcursortype( _NOCURSOR );
  96. }
  97.  
  98. // End Cursor::Cursor //
  99.  
  100. // Member Function //
  101.  
  102. #pragma argsused
  103. Cursor::Cursor( Device& theDevice )
  104.  
  105. // Description -------------------------------------------------------------
  106. //
  107. //        Copies one Cursor into another
  108. //
  109. // Parameters
  110. //
  111. //        Device&
  112. //
  113. //        The Cursor to be copied
  114. //
  115. // End ---------------------------------------------------------------------
  116. {
  117.     initialCursorState = ( ( Cursor& )theDevice ).initialCursorState;
  118.     line = ( ( Cursor& )theDevice ).line;
  119.     column = ( ( Cursor& )theDevice ).column;
  120.  
  121.     currentCursorState = ( ( Cursor& )theDevice ).currentCursorState;
  122.     oldCursorState = ( ( Cursor& )theDevice ).oldCursorState;
  123. }
  124.  
  125. // End Cursor::Cursor //
  126.  
  127. // Member Function
  128.  
  129. Cursor::~Cursor( )
  130.  
  131. // Description --------------------------------------------------------------
  132. //
  133. //        This destructor restores the normal cursor, and places the cursor
  134. //        back into the location it was when this object was created
  135. //
  136. // End ----------------------------------------------------------------------
  137. {
  138.     // Restore the cursor size using the BIOS
  139.     _setcursortype( _NORMALCURSOR );
  140.  
  141.     // Restore the cursor position
  142.     gotoxy( column, line );
  143. }
  144. // Cursor::~Cursor //
  145.  
  146. // Member Function //
  147.  
  148. classType Cursor::isA( ) const
  149.  
  150. // Description -------------------------------------------------------------
  151. //
  152. //        Returns a value representation of a class
  153. //
  154. // End ---------------------------------------------------------------------
  155. {
  156.     return cursorClass;
  157. }
  158.  
  159. // End Cursor::isA( ) //
  160.  
  161. // Member Function //
  162.  
  163. char *Cursor::nameOf( ) const
  164.  
  165. // Description -------------------------------------------------------------
  166. //
  167. //        Returns a character representation of a class
  168. //
  169. // End ---------------------------------------------------------------------
  170. {
  171.     return "Cursor";
  172. }
  173.  
  174. void Cursor::pollDevice( )
  175.  
  176. // Description -------------------------------------------------------------
  177. //
  178. //        This is a stub function, since the cursor cannot return information
  179. //
  180. // End ---------------------------------------------------------------------
  181.  
  182. {
  183. }
  184.  
  185. int Cursor::processA( Event& theEvent )
  186. {
  187.     if( theEvent.type == S_DEVICE && status != D_INACTIVE )
  188.     {
  189.         switch( theEvent.typeCode )
  190.         {
  191.             case D_ON:
  192.             case D_SHOW:
  193.                 if( currentCursorState != _NOCURSOR ) return( 0 );// Cursor on?
  194.                 _setcursortype( oldCursorState );                // Save old
  195.                 currentCursorState = oldCursorState;            // Set new
  196.                 break;
  197.             case D_OFF:
  198.             case D_HIDE:
  199.                 if( currentCursorState == _NOCURSOR ) return( 0 );// Cursor off?
  200.                 oldCursorState = currentCursorState;            // Save old
  201.                 _setcursortype( _NOCURSOR );                    // Set new
  202.                 currentCursorState = _NOCURSOR;
  203.                 break;
  204.             case D_POSITION:
  205.                 int x = theEvent.point.row;                        // Set position using
  206.                 int y = theEvent.point.column;                    // BIOS calls
  207.                 gotoxy( y, x );
  208.                 break;
  209.             case DC_INSERT:
  210.                 oldCursorState = currentCursorState;
  211.                 _setcursortype( _NORMALCURSOR );
  212.                 currentCursorState = _NORMALCURSOR;
  213.                 break;
  214.             case DC_OVERTYPE:
  215.                 oldCursorState = currentCursorState;
  216.                 _setcursortype( _SOLIDCURSOR );
  217.                 currentCursorState = _SOLIDCURSOR;
  218.                 break;
  219.         }
  220.     }
  221.     return( 0 );
  222. }
  223.